﻿using Springwater.Business.Util;
using Springwater.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Springwater.Business.ViewModels
{
    public class BorvizSummaryModel
    {
        public int Id { get; set; }
        public bool HasGps { get; set; }
        public decimal Latitude { get; set; }
        public decimal Longitude { get; set; }
        public string Nev { get; set; }
        public int MeresekSzama { get; set; }
        public int FenykepekSzama { get; set; }
        public string LegujabbFenykep { get; set; }
        public string Eredet { get; set; }

        public BorvizSummaryModel(Borviz borviz, bool longDescription = false)
        {
            this.Id = borviz.Id;

            if (borviz.FoldfelsziniHelyzet != null && borviz.FoldfelsziniHelyzet.Latitude.HasValue && borviz.FoldfelsziniHelyzet.Longitude.HasValue)
            {
                this.Latitude = borviz.FoldfelsziniHelyzet.Latitude.Value;
                this.Longitude = borviz.FoldfelsziniHelyzet.Longitude.Value;
                this.HasGps = true;
            }
            else
            {
                this.HasGps = false;
            }

            this.Nev = borviz.Elnevezes.FirstOrDefault(e => e.Elsodleges).Nev;

            if (longDescription)
            {              
                this.MeresekSzama = borviz.Meresek.Count;

                if (borviz.Fenykepek != null && borviz.Fenykepek.Count > 0)
                {
                    this.FenykepekSzama = borviz.Fenykepek.Count;
                    this.LegujabbFenykep = borviz.Fenykepek.OrderByDescending(f => f.Elsodleges).ThenByDescending(f => f.Datum).FirstOrDefault().File;
                }
                else
                {
                    this.LegujabbFenykep = "~/Images/default.jpg";
                }

                this.Eredet = borviz.Eredet;               
            }
        }
    }
}
